﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UI
{
    public partial class FCreateType : Form
    {
        private int iTypeID;
        public FCreateType()
        {
            InitializeComponent();
            iTypeID = -1;
        }
        public FCreateType(int iID)
        {
            InitializeComponent();
            iTypeID = iID;
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (iTypeID == -1)
            {
                BLL.Type typ = new BLL.Type();
                int count = FMain.typMan.TypeList.Count;
                if (count != 0)
                {
                    typ.ID = FMain.typMan.TypeList[count - 1].ID + 1;
                }
                else
                {
                    typ.ID = 1;     //Type的第一项ID为1
                }
                typ.Name = tbxTypeName.Text;
                if (cbIsincome.SelectedItem.ToString() == "收入")
                {
                    typ.Isincome = true;
                }
                else
                {
                    typ.Isincome = false;
                }
                FMain.typMan.AddType(typ);
                this.Close();
            }
            else
            {
                BLL.Type typ = new BLL.Type();
                typ.ID = iTypeID;
                typ.Name = tbxTypeName.Text;
                if (cbIsincome.SelectedItem.ToString() == "收入")
                {
                    typ.Isincome = true;
                }
                else
                {
                    typ.Isincome = false;
                }
                FMain.typMan.UpdateType(typ);
                this.Close();
            }

        }



    }
}
